#include "Tcpserver.hpp"
#include "Tcpserver.hpp"  // 处理IO的
#include "Calculator.hpp" // 处理业务的

Calculator calculator;

void DefaultOnMessagd(std::weak_ptr<Connection> conn)
{
    if (conn.expired())
        return;
    auto connection_ptr = conn.lock();
    std::cout << "上层得到的数据：" << connection_ptr->Inbuffer().c_str() << std::endl;
    std::string respond_str = calculator.Handler(connection_ptr->Inbuffer());
    if (respond_str.empty())
        return;
    INFO("%s", respond_str.c_str());

    // 发送数据
    connection_ptr->AppendOutBuffer(respond_str);
    auto tcpserver = connection_ptr->_tcp_server_ptr.lock();
    tcpserver->Sender(connection_ptr);
}

int main()
{
    std::shared_ptr<TcpServer> sv(new TcpServer(8889, DefaultOnMessagd));
    sv->Init();
    sv->Loop();

    return 0;
}